package com.ymatou.iapi.liveseller.testcase;

import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.GetProductVideoListBean;
import com.ymatou.iapi.liveseller.service.GetProductVideoListCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*商品视频列表Test
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_GetProductVideoList{
	private static GetProductVideoListBean getproductvideolistBean;
	private static GetProductVideoListCall getproductvideolistCall;
	private static LiveRoomWapper liveRoomWapper;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品视频列表Test");
	}

	@Before
	public void caseUp() {
		getproductvideolistBean=new GetProductVideoListBean();
		getproductvideolistCall=new GetProductVideoListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductvideolistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductVideoList_001() {
		Logger.start(true,"正确数据，成功");
		try {
			
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 1秒钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			Date starttime = new Date(now.getTime() + 4000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(livedto.getId(), sellerId, productId);
			LiveRoomCallService.SellerLiveOnline(livedto.getId(), sellerId);
			//开始直播录制
			LiveRoomCallService.CreateProductVideo(livedto.getId(), sellerId, productId);
			Thread.sleep(3000);
			LiveRoomCallService.StopProductVideo(livedto.getId(), productId);
			getproductvideolistBean.setProductIds(Arrays.asList(productId));
			getproductvideolistCall.setData(getproductvideolistBean);
			getproductvideolistCall.callService();			
			Logger.verifyEquals("200", getproductvideolistCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}